<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日程增加</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<body style="padding: 10px">
<form class="layui-form layui-form-pane" action="" id="Form" role="form">
    <input type="hidden" id="pkSchduleId" name="pkSchduleId"/>
    <div class="layui-form-item">
            <label class="layui-form-label" >标题</label>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input"  name="schduleTitle" lay-verify="required"
                       id="schduleTitle" type="text"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" >内容</label>
            <div class="layui-input-block">
                <textarea name="schduleContent" id="schduleContent" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-inline">
    <label class="layui-form-label">开始时间</label>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="schduleStartTime" lay-verify="required" name="schduleStartTime" placeholder="yyyy-MM-dd HH:mm:ss">
    </div>
</div>
    <div class="layui-inline">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="schduleEndTime" lay-verify="required"  name="schduleEndTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    </div>

    <div class="layui-form-item"pane="">
        <label class="layui-form-label" >是否全天</label>
        <div class="layui-input-block" id="schduleAllDay">
            <input type="radio" id="schduleAllDayyes" name="schduleAllDay" value="0" title="是" checked="">
            <input type="radio" id="schduleAllDayno"name="schduleAllDay" value="1" title="否">
        </div>
    </div>

    <hr/>
    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
            <input type="button" id="demo4" class="layui-btn layui-btn-danger" value="删除">
        </div>
    </div>
</form>

<script>

    var form = null;
    let pkSchduleId=getQueryString("pkSchduleId");
    let date=getQueryString("date");
    let show=getQueryString("show");
    // 修改赋值
    layui.use(['form', 'table', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , laydate = layui.laydate
            , form = layui.form;
        laydate.render({
            elem: '#schduleStartTime'
            ,type: 'datetime',
            trigger:'click'
        });
        laydate.render({
            elem: '#schduleEndTime'
            ,type: 'datetime',
            trigger:'click'
        });
        $("#demo4").attr("style","display:none;");
        if (pkSchduleId){
            findById(pkSchduleId);
            $("#demo4").show();
        }
        if (date){
            nowdate(date);
        }

        form.render();

        //监听提交
        form.on('submit(demo1)', function (data) {
            if(data.field.schduleStartTime > data.field.schduleEndTime){
                layer.msg("结束时间不能早于开始时间");
                return  false
            }
            debugger
            let res = postAjax(getRootPath() + "OaSchduleAction/schduleAddOrUpdate", data.field);
            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面*/
                    window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {

            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });
        $("#demo4").on("click", function () {
            layer.confirm('真的删除行么', function (index) {
                let res=deleteAjaxById(getRootPath() + 'OaSchduleAction/schduleDeleteById/' + pkSchduleId);
                if(res.code===1){
                    layer.msg('删除成功', {icon: 1});
                    setTimeout(function () {
                        formClose();
                    }, 3000);
                    setTimeout(function () {
                        parent.layui.table.reload('test');//刷新父页面
                        window.parent.location.reload();//刷新父页面
                        const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }, 3001);
                }else{
                    layer.msg("删除失败");
                }
            });
        });
    });

    function findById(pkSchduleId) {
        console.log(pkSchduleId);
        let url = getRootPath() + "/OaSchduleAction/schduleFindById/" + pkSchduleId;
        let data = getAjaxById(url);
        $("#pkSchduleId").val(data.pkSchduleId);
        $("#schduleTitle").val(data.schduleTitle);
        $("#schduleContent").val(data.schduleContent);
        $("#schduleStartTime").val(dateFormat('yyyy-MM-dd hh:mm:ss', new Date(data.schduleStartTime)));
        $("#schduleEndTime").val(dateFormat('yyyy-MM-dd hh:mm:ss', new Date(data.schduleEndTime)));
        layui.form.render("select");
        if (show){
            $("#pkSchduleId").prop("readonly",true);
            $("#schduleTitle").prop("readonly",true);
            $("#schduleContent").prop("readonly",true);
            $("#schduleStartTime").attr("disabled","disabled");
            $("#schduleEndTime").attr("disabled","disabled");
            $("#schduleAllDayyes").attr("disabled","disabled");
            $("#schduleAllDayno").attr("disabled","disabled");
        }
    }
    function nowdate(date) {
        $("#schduleStartTime").val(dateFormat('yyyy-MM-dd hh:mm:ss', new Date(date)));
    }
</script>
</body>
</html>